//
//  LTLlandView.m
//  WeiBo
//
//  Created by LiTaiLiang on 16/9/15.
//  Copyright © 2016年 LTL. All rights reserved.
//

#import "LTLlandView.h"

@interface LTLlandView()
///小房子
@property(nonatomic,strong) UIImageView *icon;
///小图标
@property(nonatomic,strong) UIImageView *image;
/**遮罩
 */
@property(nonatomic,strong) UIImageView *zheZhao;
/**提示
 */
@property(nonatomic,strong) UILabel *label;
///登录按钮
@property(nonatomic,strong) UIButton *lane;
///注册按钮
@property(nonatomic,strong) UIButton *Zhuchu;

@end

@implementation LTLlandView

-(instancetype)init
{
    if (self                      = [super init]) {
        ///背景色灰度
    self.backgroundColor          = [UIColor colorWithWhite:236/255.0 alpha:1.0];
        [self setUI];
        [self langTiter:nil imager:nil];

    }
    return self;
}
/**
 *  动画
 */
-(void)animation
{
    ///定义一个动画
    CABasicAnimation *animation   = [CABasicAnimation animation];
    ///动画属性
//    animation.keyPath = @"transform";
//
//    animation.toValue = [NSValue valueWithCGAffineTransform:CGAffineTransformMakeRotation(M_PI)];
    animation.keyPath             = @"transform.rotation";
    ///变化数值
    animation.toValue             = @(M_PI);
    ///重复
    animation.repeatCount         = MAXFLOAT;
    ///用在不断重复的动画上，当动画绑定的图层对应的视图被销毁，动画会自动被销毁
    animation.removedOnCompletion = NO;
    //1.3设置保存动画的最新状态
    animation.fillMode            = kCAFillModeForwards;
    ///时间
    animation.duration            = 15;
//    _image.transform

    [self.image.layer addAnimation:animation forKey:nil];
}
/**
 *  添加控件
 */
-(void)setUI
{
    ///小房子
    self.icon =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    ///小图标
    self.image =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    ///遮罩
    self.zheZhao =[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];

    ///提示
    self.label   = [[UILabel alloc]initText:@"关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜" font:[UIFont systemFontOfSize:18] color:[UIColor orangeColor]];
    
    ///登录按钮
    self.lane    = [[UIButton alloc]initText:@"登录" image:@"common_button_white_disable" colorText:[UIColor orangeColor]];
    ///注册按钮
    self.Zhuchu   = [[UIButton alloc]initText:@"注册" image:@"common_button_white_disable" colorText:[UIColor orangeColor]];

    //给按钮添加方法
    [self.lane addTarget:self action:@selector(longin) forControlEvents:UIControlEventTouchUpInside ];
    [self.Zhuchu addTarget:self action:@selector(zhuche) forControlEvents:UIControlEventTouchUpInside];

    [self addSubview:_image];
    [self addSubview:_zheZhao];
    [self addSubview:_icon];
    [self addSubview:_label];
    [self addSubview:_lane];
    [self addSubview:_Zhuchu];

}
/**
 *  登录
 */
-(void)longin
{
    //判断是否实现代理方法
    if ([self.deleget respondsToSelector:@selector(login)]) {

        [self.deleget login];
    }

}
/**
 *  注册
 */
-(void)zhuche
{
    //判断是否实现代理方法
    if ([self.deleget respondsToSelector:@selector(regisereg)]) {

        [self.deleget regisereg];
    }

}

/**
 *  重新布局
 */
-(void)layoutSubviews
{
    [super layoutSubviews];
    ///第三方控件自动布局
    [_icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.centerY.equalTo(self).offset(-60);
    }];
    [_image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(_icon);
    }];
    [_zheZhao mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_image);
        make.centerY.equalTo(_image).offset(-12);
    }];
    [_label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_image);
        make.top.equalTo(_zheZhao.mas_bottom);
        make.width.mas_equalTo(300);
    }];
    [_lane mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_label.mas_bottom);
        make.left.equalTo(_label.mas_left);
        make.width.mas_equalTo(120);
        make.height.mas_equalTo(35);
    }];
    [_Zhuchu mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_label.mas_bottom);
        make.right.equalTo(_label.mas_right);
        make.width.equalTo(_lane.mas_width);
        make.height.equalTo(_lane.mas_height);
    }];
}
/**
 *  设置图片及提示文字
 *
 *  @param titer  提示文字
 *  @param iamger 图片
 */
-(void)langTiter:(NSString *)titer imager:(NSString *)iamger
{
    ///判断titer是否为空而设置
    if ((titer                    = titer)) {
    self.label.text               = titer;
    self.icon.image               = [UIImage imageNamed:iamger];
    self.image.hidden             = YES;
    self.zheZhao.hidden           = YES;
    }
    ///启动动画
    [self animation];
    self.backgroundColor          = [UIColor colorWithWhite:236/255.0 alpha:1.0];
}

@end
